import request from '../utils/request';

// 项目管理相关API
export const projectApi = {
  // 获取项目列表 - 分页查询
  getProjectList: (params) => {
    return request.get('/api/project-basic-infos/page', { params });
  },

  // 获取所有项目列表
  getAllProjects: () => {
    return request.get('/api/project-basic-infos/all');
  },

  // 根据状态获取项目列表
  getProjectsByStatus: (status) => {
    return request.get(`/api/project-basic-infos/status/${status}`);
  },

  // 根据客户ID获取项目列表
  getProjectsByCustomer: (customerId) => {
    return request.get(`/api/project-basic-infos/customer/${customerId}`);
  },

  // 根据签约公司ID获取项目列表
  getProjectsByContractCompany: (contractCompanyId) => {
    return request.get(`/api/project-basic-infos/contract-company/${contractCompanyId}`);
  },

  // 获取项目详情
  getProjectDetail: (id) => {
    return request.get(`/api/project-basic-infos/${id}`);
  },

  // 根据项目编号获取项目详情
  getProjectByCode: (projectCode) => {
    return request.get(`/api/project-basic-infos/code/${projectCode}`);
  },

  // 创建项目
  createProject: (data) => {
    return request.post('/api/project-basic-infos', data);
  },

  // 更新项目
  updateProject: (id, data) => {
    return request.put(`/api/project-basic-infos/${id}`, data);
  },

  // 删除项目
  deleteProject: (id) => {
    return request.delete(`/api/project-basic-infos/${id}`);
  },

  // 作废项目（状态变为作废审批中）
  voidProject: (id) => {
    return request.put(`/api/project-basic-infos/${id}/void`);
  },

  // 获取项目成员
  getProjectMembers: (projectId) => {
    return request.get(`/api/projects/${projectId}/members`);
  },

  // 添加项目成员
  addProjectMember: (projectId, data) => {
    return request.post(`/api/projects/${projectId}/members`, data);
  },

  // 移除项目成员
  removeProjectMember: (projectId, memberId) => {
    return request.delete(`/api/projects/${projectId}/members/${memberId}`);
  },

  // 获取项目卡片列表（按项目编号分组统计）
  getProjectCards: () => {
    return request.get('/api/project-cards');
  },

  // 根据状态获取项目卡片列表
  getProjectCardsByStatus: (status) => {
    return request.get(`/api/project-cards/status/${status}`);
  },

  // 根据客户ID获取项目卡片列表
  getProjectCardsByCustomer: (customerId) => {
    return request.get(`/api/project-cards/customer/${customerId}`);
  },

  // 根据项目编号获取子项目列表
  getSubProjectsByProjectCode: (projectCode) => {
    return request.get(`/api/project-cards/${projectCode}/subprojects`);
  },

  // 根据项目编号获取验收单列表
  getAcceptancesByProjectCode: (projectCode) => {
    return request.get(`/api/project-cards/${projectCode}/acceptances`);
  },

  // 根据验收单ID获取验收成员列表
  getAcceptanceMembers: (acceptanceId) => {
    return request.get(`/api/project-cards/acceptance/${acceptanceId}/members`);
  },

  // 根据项目编号获取分包项目列表
  getSubcontractProjectsByProjectCode: (projectCode) => {
    return request.get(`/api/project-cards/${projectCode}/subcontract-projects`);
  },

  // 获取项目结算信息
  getProjectSettlement: (projectId) => {
    return request.get(`/api/projects/${projectId}/settlement`);
  },

  // 更新项目结算
  updateProjectSettlement: (projectId, data) => {
    return request.put(`/api/projects/${projectId}/settlement`, data);
  },

  // 获取子项目列表
  getSubProjects: (projectId) => {
    return request.get(`/api/projects/${projectId}/sub-projects`);
  },

  // 创建子项目
  createSubProject: (projectId, data) => {
    return request.post(`/api/projects/${projectId}/sub-projects`, data);
  },

  // 更新子项目
  updateSubProject: (projectId, subProjectId, data) => {
    return request.put(`/api/projects/${projectId}/sub-projects/${subProjectId}`, data);
  },

  // 删除子项目
  deleteSubProject: (projectId, subProjectId) => {
    return request.delete(`/api/projects/${projectId}/sub-projects/${subProjectId}`);
  },

  // 获取项目统计信息
  getProjectStatistics: (projectId) => {
    return request.get(`/api/projects/${projectId}/statistics`);
  },

  // 获取项目风险信息
  getProjectRisks: (projectId) => {
    return request.get(`/api/projects/${projectId}/risks`);
  },

  // 添加项目风险
  addProjectRisk: (projectId, data) => {
    return request.post(`/api/projects/${projectId}/risks`, data);
  },

  // 更新项目风险
  updateProjectRisk: (projectId, riskId, data) => {
    return request.put(`/api/projects/${projectId}/risks/${riskId}`, data);
  },

  // 删除项目风险
  deleteProjectRisk: (projectId, riskId) => {
    return request.delete(`/api/projects/${projectId}/risks/${riskId}`);
  },

  // 获取项目详情（包括关联的合同和验收单）
  getProjectDetailWithRelations: (id) => {
    return request.get(`/api/project-basic-infos/${id}/detail`);
  },

  // 根据项目ID获取合同列表
  getContractsByProjectId: (projectId) => {
    return request.get(`/api/project-contracts/project/${projectId}`);
  },

  // 根据项目ID获取验收单列表
  getAcceptancesByProjectId: (projectId) => {
    return request.get(`/api/project-acceptance/project/${projectId}`);
  },

  // 根据合同ID获取合同人员列表
  getContractPersonnelByContractId: (contractId) => {
    return request.get(`/api/contract-personnel/contract/${contractId}`);
  },

  // 根据项目编号获取合同人员列表
  getContractPersonnelByProjectCode: (projectCode) => {
    return request.get(`/api/contract-personnel/project/${projectCode}`);
  }
};
